package logic

import (
	"MyBlogv2/Servers/Article/article"
	"MyBlogv2/Servers/Article/internal/svc"
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/models"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateArticleStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateArticleStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateArticleStatusLogic {
	return &UpdateArticleStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateArticleStatusLogic) UpdateArticleStatus(in *Article.UpdateArticleStatusRequest) (*Article.CommonResponse, error) {
	id := in.Id
	status := in.Status
	models.Db.Model(new(models.Article)).Where("id = ?", id).Update("status", status)

	return &Article.CommonResponse{
		Code: int64(HttpCode.SUCCESS),
	}, nil
}
